package com.hpf.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hpf.domain.WmsSupplier;
import com.hpf.service.WmsSupplierService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

@Controller
@RequestMapping("/wms/supplier")
public class WmsSupplierController extends BaseController{

	private String prefix="wms/supplier";
	@Autowired
	private WmsSupplierService service;
	//供应商列表
	@GetMapping()
	public String index() {
		return prefix+"/supplier";
	}
	
	@PostMapping("/list")
	@ResponseBody()
	public TableDataInfo list(WmsSupplier supplier) {
		logger.info(supplier.toString());
		startPage();
        List<WmsSupplier> list = service.listWmsSupplier(supplier);
        return getDataTable(list);
	 }
	
	
	@GetMapping("/add")	
	public String add() {
		return prefix+"/add";
	}
	
	@Log(title="wms供应商",businessType=BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(@Validated WmsSupplier wmsSupplier)
	{        
        return toAjax(service.insertWmsSupplier(wmsSupplier));
    }
	
	@GetMapping("/edit/{id}")
	public String edit(ModelMap map,@PathVariable("id") int id) {
		map.put("supplier", service.getWmsSupplierById(id));
		return prefix+"/edit";
	}
	
	@Log(title="wms供应商",businessType=BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult updateSave(@Validated WmsSupplier wmsSupplier) {
		return toAjax(service.updateWmsSupplier(wmsSupplier));
	}
	
//	@Log(title="wms供应商",businessType=BusinessType.DELETE)
//	@PostMapping("/remove/{id}")
//	@ResponseBody
//	public AjaxResult remove(@PathVariable("id") int id) {
//		return toAjax(service.deleteWmsSupplier(id));
//	}
	
	@Log(title="wms供应商",businessType=BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult batchRemove(String ids) {
		return toAjax(service.deleteWmsSupplierByIds(ids));
	}
}
